const calculate = (s) => {
    s = s.split('');
    let cnt = 0;
    let b = 0; // '```' 出现的次数，次数 / 3是偶数则可以计数，否则不计数
    let flag = true; // 判断是否要执行统计字符功能
    s.forEach((item) => {
        if (item == '\n') {
            return;
        }
        if (item == '`') {
            b++;
        }
        if (b % 3 == 0 && ((b / 3) % 2) != 0) {
            flag = false;
        } else if (b % 3 == 0 && ((b / 3) % 2) == 0) {
            flag = true;
        }
        if (flag == false) {
            return;
        }
        if (item.charCodeAt() >= 19968 && item.charCodeAt() <= 40869 || item.charCodeAt() >= 97 && item.charCodeAt() <= 122 || item.charCodeAt() >= 65 && item.charCodeAt() <= 90 || item >= 0 && item <= 9 && item !== ' ') {
            cnt++;
        }
    })
    return cnt;
}

//防抖函数
const debounce = (func, delay) => {
    let timer;
    return function() {
        const that = this;
        let args = arguments;
        clearTimeout(timer)
        timer = setTimeout(() => {
            func.call(that, args);
        }, delay);
    }
}

const filterTime = (s) => {
    //"2021-11-21T16:00:00.000+0000"
    let year = s.substr(0, 4);
    let month = s.substr(5, 2);
    let day = s.substr(8, 2);
    let time = s.substr(11, 8);
    s = year + '年' + month + '月' + day + '日 ' + time;
    return s;
}

export default {
    calculate,
    debounce,
    filterTime,
}